package com.lanyam.travel.base.service.impl;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.lanyam.travel.base.entity.DistrTramMember;
import com.lanyam.travel.base.entity.vo.DistrTramMemberVo;
import com.lanyam.travel.base.dao.DistrTramMemberMapper;
import com.lanyam.travel.base.service.IDistrTramMemberService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;


@Service
@Transactional
@Slf4j
public class DistrTramMemberServiceImpl implements IDistrTramMemberService {

    @Resource
    private DistrTramMemberMapper distrTramMemberMapper;

    @Override
    public IPage<DistrTramMemberVo> getPageDistrTramMember (Map<String, Object> queryMap, Integer page, Integer rows) {
        Page<DistrTramMemberVo> pageSize = new Page<DistrTramMemberVo>(page, rows);
        Page<DistrTramMemberVo> pageInfo = distrTramMemberMapper.getPage(pageSize, queryMap);
        return pageInfo;
    }

    @Override
    public void addDistrTramMember(DistrTramMember distrTramMember) {
        Map<String, Object> queryMap =new HashMap<>();
        queryMap.put("teamId",distrTramMember.getTeamId());
        queryMap.put("memberUserid",distrTramMember.getMemberUserid());
        List c = distrTramMemberMapper.selectByMap(queryMap);
        if(CollectionUtils.isNotEmpty(c)){
            throw new RuntimeException("用户不能重复添加");
        }
        distrTramMemberMapper.insert(distrTramMember);
    }

    @Override
    public void updateDistrTramMember(DistrTramMember distrTramMember) {
        distrTramMemberMapper.updateById(distrTramMember);
    }

    @Override
    public void delById(String id) {
        distrTramMemberMapper.delById(id);
    }

    @Override
    public IPage<DistrTramMemberVo> getPageOfUserInfoByTeamId(Map<String, Object> queryMap, Integer page, Integer rows) {
        Page<DistrTramMemberVo> pageSize = new Page<DistrTramMemberVo>(page, rows);
        Page<DistrTramMemberVo> pageInfo = distrTramMemberMapper.getPageOfUserInfoByTeamId(pageSize, queryMap);
        return pageInfo;
    }
}